﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BG_Manage_BG_Comments : System.Web.UI.Page
{
    VPINews.BLL.Comments bll_com = new VPINews.BLL.Comments();
    VPINews.Model.Comments mod_com = new VPINews.Model.Comments();
    private static int linkid;

    protected void Page_Load(object sender, EventArgs e)
    {
        getComments();

    }
    protected void getComments()
    {
        GridView1.DataSource = bll_com.GetAllList();
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSource = bll_com.GetAllList();
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        VPINews.BLL.Comments bll_com = new VPINews.BLL.Comments();
        VPINews.Model.Comments mod_com = bll_com.GetModel(Convert.ToInt32(e.CommandArgument));

        if (e.CommandName == "DeleteComments")
        {
            bll_com.Delete(Convert.ToInt32(e.CommandArgument));
            getComments();
        }

        if (e.CommandName == "EditComments")
        {

            this.txtComments.Value = mod_com.Contents;
            linkid =mod_com.CmtID;
            this.hdID.Value = linkid.ToString();
        }

    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            int linkid = Convert.ToInt32(hdID.Value);

            if (linkid > 0)
            {
                mod_com.CmtID = linkid;
                mod_com.Contents = this.txtComments.Value.Trim();
                mod_com.CreateTime = DateTime.Now;

                bll_com.Update(mod_com);
                smslabel.Text = "评论修改成功";

                txtComments.Value = "";
                hdID.Value = "0";

            }
        }

    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        this.txtComments.Value = "";

    }
}
